package com.liuzu.esys.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liuzu.esys.common.LayuiPageVo;
import com.liuzu.esys.mapper.VipinformMapper;
import com.liuzu.esys.pojo.Vipinform;
import com.liuzu.esys.service.VipinformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("VipinformService")
public class VipinformServiceImpl implements VipinformService {
    @Autowired
    private VipinformMapper vipinformMapper;

    /**
     *分页查询操作
     */
    @Override
    public LayuiPageVo<Vipinform> vipinformPageData(Map<String, Object> params) {
        //mybatis 的分页插件
        Integer page = Integer.parseInt(params.get("page") + "");

        Integer limit = Integer.parseInt(params.get("limit") + "");

        PageHelper.startPage(page, limit);

        List<Vipinform> messages = vipinformMapper.selectByParams(params);

        //mybatis 的分页数据结构
        PageInfo<Vipinform> vipinforms = new PageInfo<>(messages);

        //把mybatis 的分页数据封装到 layui 的分页数据结构中
        LayuiPageVo<Vipinform> messageLayuiPageVo = new LayuiPageVo<>();
        messageLayuiPageVo.setCode(0); //layui 默认0 是正确状态
        messageLayuiPageVo.setMsg("分页列表数据");  //提示信息
        messageLayuiPageVo.setCount(vipinforms.getTotal());//总记录数
        messageLayuiPageVo.setData(vipinforms.getList());

        return messageLayuiPageVo;
    }

    @Override
    public boolean vipinformAdd(Vipinform vipinform) {
        boolean flag = false;
        int a = vipinformMapper.VipinformAdd(vipinform);
        if(a==1){
            return flag = true;
        }else {
            return flag = false;
        }

    }

    @Override
    public int vipinformDel(Integer id) {
        int i =  vipinformMapper.VipinformDel(id);
        return i;
    }

}
